<?php
	require '../db_config.php';

	$result = '';
	$user = $_POST['username'];
	$pass = $_POST['password'];
	
	mysql_connect(__DB_HOST__, __DB_USER__, __DB_PASSWORD__) or die(mysql_error());
	mysql_query('use ' . __DB_DATABASE__ . ';') or die('Invalid query: ' . mysql_error());
	$result = mysql_query('SELECT en FROM site_fields WHERE description=\'admin\';') or die('Invalid query: ' . mysql_error());
	$arr = mysql_fetch_array($result);
	$password = $arr['en'];
		
	if ($user == 'admin' && sha1($pass) == $password) {
		$result = "<center>";
		$result = $result.'Login successful';
		$result = $result."</br>"."<input type=\"button\" value=\"Admin panel\" onClick=\"location.href='index.php'\"/>";
		$result = $result."</center>";
		session_start();
		$_SESSION['user'] = 1;
	} else {
		$result = "<center>";
		$result = $result.'Login failed';
		$result = $result."</br>"."<input type=\"button\" value=\"try again\" onClick=\"location.href='login.php'\"/>";
		$result = $result."</center>";
	}
	echo $result;
?>
